package com.gaohe.official.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gaohe.common.log.annotation.Log;
import com.gaohe.common.log.enums.BusinessType;
import com.gaohe.common.security.annotation.RequiresPermissions;
import com.gaohe.official.domain.FmBulletin;
import com.gaohe.official.service.IFmBulletinService;
import com.gaohe.common.core.web.controller.BaseController;
import com.gaohe.common.core.web.domain.AjaxResult;
import com.gaohe.common.core.utils.poi.ExcelUtil;
import com.gaohe.common.core.web.page.TableDataInfo;

/**
 * 系统公告Controller
 * 
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/bulletin")
public class FmBulletinController extends BaseController
{
    @Autowired
    private IFmBulletinService fmBulletinService;

    /**
     * 查询系统公告列表
     */
    @RequiresPermissions("official:bulletin:list")
    @GetMapping("/list")
    public TableDataInfo list(FmBulletin fmBulletin)
    {
        startPage();
        List<FmBulletin> list = fmBulletinService.selectFmBulletinList(fmBulletin);
        return getDataTable(list);
    }

    /**
     * 导出系统公告列表
     */
    @RequiresPermissions("official:bulletin:export")
    @Log(title = "系统公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmBulletin fmBulletin)
    {
        List<FmBulletin> list = fmBulletinService.selectFmBulletinList(fmBulletin);
        ExcelUtil<FmBulletin> util = new ExcelUtil<FmBulletin>(FmBulletin.class);
        util.exportExcel(response, list, "系统公告数据");
    }

    /**
     * 获取系统公告详细信息
     */
    @RequiresPermissions("official:bulletin:query")
    @GetMapping(value = "/{bulletinId}")
    public AjaxResult getInfo(@PathVariable("bulletinId") Long bulletinId)
    {
        return success(fmBulletinService.selectFmBulletinByBulletinId(bulletinId));
    }

    /**
     * 新增系统公告
     */
    @RequiresPermissions("official:bulletin:add")
    @Log(title = "系统公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmBulletin fmBulletin)
    {
        return toAjax(fmBulletinService.insertFmBulletin(fmBulletin));
    }

    /**
     * 修改系统公告
     */
    @RequiresPermissions("official:bulletin:edit")
    @Log(title = "系统公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmBulletin fmBulletin)
    {
        return toAjax(fmBulletinService.updateFmBulletin(fmBulletin));
    }

    /**
     * 删除系统公告
     */
    @RequiresPermissions("official:bulletin:remove")
    @Log(title = "系统公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bulletinIds}")
    public AjaxResult remove(@PathVariable Long[] bulletinIds)
    {
        return toAjax(fmBulletinService.deleteFmBulletinByBulletinIds(bulletinIds));
    }
}
